var loadDataUrl = '/ajax/more.html'; // 获取更多数据URL

var $dropload = $('#dropload');

var getItem = function(data){
    return '<li>'+
        '<img src="'+ data.avat +'">'+
        '<div class="detail">'+
            '<span class="name">'+ data.name +'</span><br>'+
            '<span class="ip">('+ data.ip +')</span><br>'+
            '<span class="times">参与了<i>'+ data.times +'</i>人次<em>'+ data.time +'</em></span>'+
        '</div>'+
    '</li>';
};

$dropload.dropload({
    scrollArea: window,
    loadUpFn: function(me){
        $.get(loadDataUrl, function(data){
            if(data.retcode == 0){
                // 成功取到数据
                // data:{retcode:0,retdesc:"拉取数据成功",result:[{name:"figo",avat:'xxx.jpg',city:"",ip:"北京 IP:0.0.0.0",times:3,time:"2016-7-13 12:16:33"}]}
                var htm = '';
                $.each(data.result,function(){
                    htm += getItem(this);
                });
                $dropload.append(htm); // 在顶部插入新数据
                // $dropload.html(htm); 全部覆盖替换
            }else{
                // error
                // console.log("数据拉取失败");
            }
            me.resetload();
        },'json').fail(function(){
            console.log('network error');
            me.resetload();
        });
    },
    loadDownFn: function(me){
        $.get(loadDataUrl, function(data){
            if(data.retcode == 0){
                // 成功取到数据
                // data:{retcode:0,retdesc:"拉取数据成功",result:[{name:"figo",avat:'xxx.jpg',city:"",ip:"北京 IP:0.0.0.0",times:3,time:"2016-7-13 12:16:33"}]}
                var htm = '';
                $.each(data.result,function(){
                    htm += getItem(this);
                });
                $dropload.append(htm); // 在底部插入新数据
            }else{
                // error
                // console.log("数据拉取失败");
            }
            me.resetload();
        },'json').fail(function(){
            console.log('network error');
            me.resetload();
        });
    },
    domUp: {
        domRefresh : '<div class="dropload-refresh">下拉刷新</div>',
        domUpdate : '<div class="dropload-update">释放更新</div>'
    },
    domDown: {
        domRefresh : '<div class="dropload-refresh">加载中...</div>',
        domLoad : '<div class="dropload-load">加载中...</div>'
    }
});